<%@ page language="java"  pageEncoding="UTF-8"%>
<%@ page import = "java.util.*" %>
<%@ include file="../include/taglib.jsp"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
  <head>
    <title>history-event-common</title>
 	<%@ include file="../include/common.jsp"%>
	<%@ include file="../include/jbox.jsp"%>
	<%@ include file="../include/table.jsp"%>
	<%@ include file="../include/tree.jsp"%>
	<%@ include file="../include/tooltip.jsp"%>
	<script type="text/javascript" src="${pageContext.request.contextPath}/js/calendar/zh_CN_WdatePicker.js"></script>
	<style type="text/css">
		.ztree {border: 1px solid #617775;background: #f0f6e4;width:220px;height:360px;overflow-y:scroll;overflow-x:auto;}
		.eventlevel2 {background-position-x:left;}
		.eventlevel3 {background-position-x:left;}
		.eventlevel4 {background-position-x:left;}
		.eventlevel5 {background-position-x:left;}
		.status0 {background-position-x:left;}
		.status1 {background-position-x:left;}
		.status2 {background-position-x:left;}
		.renlin{
			background:url(../style/default/bsm/images/ack.gif) no-repeat 12px 3px;
		}
		.clear_1{
			background:url(../style/default/bsm/images/confirm.gif) no-repeat 12px 3px;		
		}
	</style>
	<script type="text/javascript">
	function datagrid(){
		var oTable=	$('#depmtList').dataTable();
		oTable.fnPageChange("first",true);
	}
	function cancelAllCheck(){
		$("#dt_check_all").removeAttr("checked");
	}
	refreshResSearch=function(resId,resName){
		if(resName == ''){
			$("#resDiv").css({"display":"none"});
		}else{
			$("#resDiv").css({"display":""});
		}
		$("#resSearch").html(resName);
		$("#resId").val(resId);
	}
	refreshTable=function(scope,scopeName){
		if(scopeName == ''){
			$("#dimensionDiv").css({"display":"none"});
		}else{
			$("#dimensionDiv").css({"display":""});
		}
		$("#dimensionSearch").html(scopeName);
		$("#dimension").val(scope);
	}
	function delDiv(id){
		window.parent.delDiv(id);
	}
	function delResDiv(id){
		window.parent.delResDiv(id);
	}
	function closeIt(){
		$(document).trigger('hideCluetip');
	}
	
	$(function(){
		$('#beginDate').val('${beginDate}');
		$('#endDate').val('${endDate}');
		
		if(parent.document.getElementById("resName").value == ''){
			$("#resDiv").css({"display":"none"});
		}else{
			$("#resDiv").css({"display":""});
		}
		$("#resSearch").html(parent.document.getElementById("resName").value);
		$("#resId").val(parent.document.getElementById("resId").value);
		
		if(parent.document.getElementById("scopeName").value == ''){
			$("#dimensionDiv").css({"display":"none"});
		}else{
			$("#dimensionDiv").css({"display":""});
		}
		$("#dimensionSearch").html(parent.document.getElementById("scopeName").value);
		$("#dimension").val(parent.document.getElementById("scope").value);
		
		if($('#confirmtype').val()!= 1)
			$('#confirmer').attr('disabled',false);
    	
		//加载grid
		var oTable=	$('#depmtList').dataTable({
			"bProcessing": true, 
			"bServerSide": true,
			"sServerMethod": 'POST',
			"sAjaxSource":'${pageContext.request.contextPath}/event/history-event!list.action?scope='+'${scope}',
			"bPaginate": true,
			"bSort": true,
			"bFilter":false,
			"bJQueryUI":false,
			"sPaginationType": "full_numbers",
			//"sScrollX":'100%',
			"sDom":'rt<"bottom"flpi>',
			"aLengthMenu": [[10, 20, 50, 100], [10, 20, 50,100]],
			"aoColumns":[
				{"mDataProp":"checkbox","bSortable": false},
				{"mDataProp":"status","bSortable": false,
					"fnCreatedCell" : function(nTd, sData,oData, iRow,iCol) {
						var statusName = oData.statusName;
						var ss = "<a>"+ statusName +"</a>";
						$(nTd).html(ss);
				}},
				{"mDataProp":"levelName"},
				{"mDataProp":"msg","bSortable": false},
				{"mDataProp":"eventTypeName","bSortable": false},
				{"mDataProp":"resName","bSortable": false},
				{"mDataProp":"occurTime"},
				{"mDataProp":"confirmer","bSortable": false},
				{"mDataProp":"id","bVisible":false}
			], 
			 "oLanguage": { 
			 				"sLengthMenu": "每页 _MENU_ 条",
			 		 		"sZeroRecords": "  ",
							"sInfo": "当前从 _START_ 到 _END_ 条,共 _TOTAL_ 条记录", 
							"sInfoEmpty": "没有找到记录",
							"oPaginate":{"sFirst":"首页","sPrevious":"上一页","sNext":"下一页","sLast":"尾页"}	
			},
		    "fnServerParams":function(aoData){
		    	//级别
		    	var str=document.getElementsByName("level");
		    	var objarray=str.length;
		    	var level = new Array();
		    	var j = 0;
		    	for (i=0;i<objarray;i++)
		    	{
		    	  if(str[i].checked == true)
		    	  {
		    		  level[j++]=(str[i].value);
		    	  }
		    	}
		    	if(level !='')
		    	{
		    		aoData.push({'name':'level','value':level});
		    	}
		    	//状态
		    	var statusStr=document.getElementsByName("status");
		    	var statusArray=statusStr.length;
		    	var status = new Array();
		    	var k = 0;
		    	for (i=0;i<statusArray;i++)
		    	{
		    	  if(statusStr[i].checked == true)
		    	  {
		    		  status[k++]=(statusStr[i].value);
		    	  }
		    	}
		    	if(status !='')
		    	{
		    		aoData.push({'name':'status','value':status});
		    	}
		    	//时间
		    	var beginDate = $('#beginDate').val();
		    	if(beginDate!='')
		    	{
		    		aoData.push({'name':'beginDate','value':beginDate});
		    	}
		    	var endDate = $('#endDate').val();
		    	if(endDate!='')
		    	{
		    		aoData.push({'name':'endDate','value':endDate});
		    	}
		    	//清除类型
		    	var confirmtype = $('#confirmtype').val();
		    	if(confirmtype!='')
		    	{
		    		aoData.push({'name':'confirmtype','value':confirmtype});
		    	}
		    	//清除人
		    	var confirmer = $('#confirmer').val();
		    	if(confirmer!='')
		    	{
		    		aoData.push({'name':'confirmer','value':confirmer});
		    	}
		    	//维度范围
		    	if('$("#dimension").val()' != ''){
		    		aoData.push({'name':'dimension','value':$("#dimension").val()});
		    	}
		    	//资源ID范围
		    	if('$("#resId").val()' != ''){
		    		aoData.push({'name':'resId','value':$("#resId").val()});
		    	}
		    },
		    "fnRowCallback":function( nRow, aData, iDisplayIndex, iDisplayIndexFull )
			{		
			},
			 "fnDrawCallback": function () {
		    }
	});
		$('#depmtList tbody td :checkbox').live('click', function (e) {
			var nTr = $(this).parents('tr')[0]; 
		    	showDetailFlag = true;
			   if ($(nTr).hasClass('row_selected')) {
				  	$(nTr).removeClass('row_selected'); 
				  	$("#dt_check_all").removeAttr("checked");
				  	cancelAllCheck();
			  }else
			  {
			  		$(nTr).addClass('row_selected'); 
			 }
			 if(!$(this).attr("checked")){
			 	$('#allCheck').attr("checked",false);
			 }
		});
		showDetailFlag = false;
		$('#depmtList tbody tr').live('click', function (e) {
			if(showDetailFlag){
			 	showDetailFlag = false;
			 	return;
			 }
			 var nTds = $('td', this);
		      if ( $(this).hasClass('row_selected') ) {
				  	$(this).removeClass('row_selected'); 
			  }else
			  {
			  		$(this).addClass('row_selected'); 
			 }
			if(oTable.fnGetData( this ) != null){
				//显示明细
				if ( oTable.fnIsOpen(this) ) {
					oTable.fnClose( this ); 
				}else{
					oTable.fnOpen(this,fnFormatDetails(oTable,this),'details');
				}
			}
		});
	});
	//全选和取消全选
    function allClick(isSigle)
    {
    	if(isSigle!=1) //如果是单选就不支持全选
	    	{
	    		var dt_check_all = $('#dt_check_all').attr("checked");
  	    	var allCheckbox = $("input[name='dt_check']");
  	    	if(dt_check_all)
  	    	{
  	    		
  	    		allCheckbox.attr("checked",allCheckbox);  //全选
  	    		$('#depmtList tbody tr').addClass('row_selected');  //背景色全选
  	    	}else
  	    	{
  	    		allCheckbox.attr("checked",false);   //取消全选
  	    		$('#depmtList tbody tr').removeClass('row_selected');  //背景色取消
  	    	}
	    	}
    }
	function fnFormatDetails ( oTable, nTr ) {    
		var aData = oTable.fnGetData( nTr ); 
	var sOut = '<table cellpadding="5"  cellspacing="0" border="0" style="padding-left:50px; float: left;">'; 
	 $.ajax({
			type:'post',
			url:'${pageContext.request.contextPath}/event/history-event!ackAndConfirmDetails.action',
			data:{id:aData.id},
			global:false,
			async:false,
			cache:false,
			dataType:'json',
			success:function(data,textStatus){
				if(data.length<=0){
					sOut += '<tr><td>无数据</td></tr>';
				}else{
					sOut += '<tr><td class="text-a-r">资源地址：</td><td>'+data.ip+'</td></tr>'; 
					if(data.ack != ''){
						sOut +=  '<tr><td class="text-a-r" >认领人：</td><td>'+data.ack+'</td></tr>';
					}
					if(data.ackTime != ''){
						sOut +=  '<tr><td class="text-a-r" >认领时间：</td><td>'+data.ackTime+'</td></tr>';
					}
					if(data.confirm != ''){
						sOut +=  '<tr><td class="text-a-r">清除人：</td><td>'+data.confirm+'</td></tr>';			
					}
					if(data.confirmTime != ''){
						sOut +=  '<tr><td class="text-a-r">清除时间：</td><td>'+data.confirmTime+'</td></tr>';
					}
					sOut += '<tr><td class="text-a-r">检测次数：</td><td>'+data.count+'</td></tr>';  
					sOut += '<tr><td class="text-a-r">最后检测时间：</td><td>'+data.lastOccurTime+'</td></tr>';     
				}
			},
			error:function(){
				getTopWin(window).getMessageBox().alert('服务器内部错误,请联系管理员','错误');
			}
	  });
		 sOut += '</table>';           
		 return sOut;
} 
	//得到当前选中的
	function fnGetSelected() {   
		var selections = $("input[name='dt_check']:checked");
		return selections;
	} 
	
	function search(){
		var oTable=	$('#depmtList').dataTable();
		oTable.fnPageChange("first",true);
	}
	
	function eventDown(){
		var str=document.getElementsByName("level");
    	var objarray=str.length;
    	var level = new Array();
    	var j = 0;
    	for (i=0;i<objarray;i++)
    	{
    	  if(str[i].checked == true)
    	  {
    		  level[j++]=(str[i].value);
    	  }
    	}
    	//状态
    	var statusStr=document.getElementsByName("status");
    	var statusArray=statusStr.length;
    	var status = new Array();
    	var k = 0;
    	for (i=0;i<statusArray;i++)
    	{
    	  if(statusStr[i].checked == true)
    	  {
    		  status[k++]=(statusStr[i].value);
    	  }
    	}
    	var beginDate = $('#beginDate').val();
    	var endDate = $('#endDate').val();
    	var confirmer = $('#confirmer').val();
    	var confirmtype = $('#confirmtype').val();
		window.location="${pageContext.request.contextPath}/event/event-his-export!doExport.action?level="+level+"&beginDate="+beginDate+"&endDate="+endDate+"&dimension="+$("#dimension").val()+"&status="+status+"&resId="+$("#resId").val()+"&confirmer="+confirmer+"&confirmtype="+confirmtype;
	}
		function batchConfirm(){
			var rows = fnGetSelected();
			if(rows.length>0){
				var id = new Array(rows.length);
				var oTable =$('#depmtList').dataTable();
				for(var i = 0 ; i<rows.length;i++){
					id[i] = rows[i].value;
				}
				//校验是否有权限
				$.ajax({
					   type: "POST", 
					   url: "${pageContext.request.contextPath}/event/active-event!handelAuth.action?id="+id, //请求的action
					   data: "", //传的参数
					   dataType: 'json',
					   success: function(data){ //结果
						   if(data == true){
							 //校验是否包含已认领事件
							   $.ajax({
								   type: "POST", 
								   url: "${pageContext.request.contextPath}/event/active-event!confirmCheck.action?id="+id, //请求的action
								   data: $("#myform").serialize(), //传的参数
								   dataType: 'json',
								   success: function(data){ //结果
									   if(data == true){
										   var url ="iframe:event/active-event!delete.action?id="+id;
											var opt = { title: "批量清除活动事件",width:600,height:280,buttons: {}};
											getTopWin(window).openjBox(url,opt,'confirm-active-event',window);
									   }else{
										   datagrid();
										   getTopWin(window).getMessageBox().alert("包含已清除事件","提示");
									   }
								   }
							});
						   }else{
							   getTopWin(window).getMessageBox().alert("没有清除权限","提示");
						   }
					   }
				});
			}else{
				getTopWin(window).getMessageBox().alert("请选择一条数据","提示");
			}
		}
		function batchAck(){
			var rows = fnGetSelected();
			if(rows.length>0){
				var id = new Array(rows.length);
				var oTable =$('#depmtList').dataTable();
				for(var i = 0 ; i<rows.length;i++){
					id[i] = rows[i].value;
				}
				//校验是否有权限
				$.ajax({
					   type: "POST", 
					   url: "${pageContext.request.contextPath}/event/active-event!handelAuth.action?id="+id, //请求的action
					   data: "", //传的参数
					   dataType: 'json',
					   success: function(data){ //结果
						   if(data == true){
							 //校验是否包含已认领事件
								$.ajax({
									   type: "POST", 
									   url: "${pageContext.request.contextPath}/event/active-event!ackCheck.action?id="+id, //请求的action
									   data: $("#myform").serialize(), //传的参数
									   dataType: 'json',
									   success: function(data){ //结果
										   if(data == true){
											   	var url ="iframe:event/active-event!input.action?id="+id;
												var opt = { title: "批量认领活动事件",width:600,height:180,buttons: {}};
												getTopWin(window).openjBox(url,opt,'ack-active-event',window);
										   }else{
											   datagrid();
											   getTopWin(window).getMessageBox().alert("包含已认领或清除事件","提示");
										   }
									   }
								});
						   }else{
							   getTopWin(window).getMessageBox().alert("没有认领权限","提示");
						   }
					   }
				});
			}else{
				getTopWin(window).getMessageBox().alert("请选择一条数据","提示");
			}
	}
	function showMessage(message){
		window.setTimeout(function () { $.jBox.tip(message, 'success'); }, 100);
	}
	</script>
  </head>
  
  <body>
  	<div id="menuContent" style="display:none; position: absolute;z-index:100;">
		<ul id="treeDemo" class="ztree" style="margin-top:0; width:200px; height: 200px;"></ul>
	</div>
	
  	<div class="searchFormStyle">
  		<div id="resDiv" style="display: none;">
  			<label>资源名称：</label>
			<span id="resSearch" style="float: left;"></span>
			<input type="hidden" id="resId" name="resId"/>
  		</div>
  		<div id="dimensionDiv" style="display: none;">
  			<label>资源类别：</label>
			<span id="dimensionSearch" style="float: left;"></span>
			<input type="hidden" id="dimension" name="dimension"/>
  		</div>
  		<div>
  			<label>事件级别：</label>
			<input type="checkbox" name="level" id="level1" value="2" checked="checked"><label class="eventlevel2" style="padding-left: 20px; margin-left:3px; width: 30px;">轻微</label>
			<input type="checkbox" name="level" id="level2" value="3" checked="checked"><label class="eventlevel3" style="padding-left: 20px; margin-left:3px; width: 30px;">警告</label>
			<input type="checkbox" name="level" id="level3" value="4" checked="checked"><label class="eventlevel4" style="padding-left: 20px; margin-left:3px; width: 30px;">重要</label>
			<input type="checkbox" name="level" id="level4" value="5" checked="checked"><label class="eventlevel5" style="padding-left: 20px; margin-left:3px; width: 30px;">严重</label>
  			<label>&nbsp;&nbsp;&nbsp;&nbsp;事件状态：</label>
			<input type="checkbox" name="status" id="status1" value="0" checked="checked"><label class="status0" style="padding-left: 20px; margin-left:3px; width: 40px;">未认领</label>
			<input type="checkbox" name="status" id="status2" value="1" ><label class="status1" style="padding-left: 20px; margin-left:3px; width: 40px;">已认领</label>
			<input type="checkbox" name="status" id="status2" value="2" ><label class="status2" style="padding-left: 20px; margin-left:3px; width: 40px;">已清除</label>
  		</div>
  		<span>
  			<label>产生时间：</label>
			<input id="beginDate" name="beginDate" class="Wdate" type="text" onclick="WdatePicker({dateFmt:'yyyy-MM-dd HH:mm',maxDate:'%y-%M-%d %H:%m',readOnly:true})"/>
			<label>-</label>
			<input id="endDate" name="endDate" class="Wdate" type="text" onclick="WdatePicker({dateFmt:'yyyy-MM-dd HH:mm',minDate:$('#beginDate').val(),readOnly:true})"/>
  			<label>&nbsp;&nbsp;&nbsp;&nbsp;清除类型：</label>
  			<select name="confirmtype" id="confirmtype" style="float:left; width:100px; ">
  			 	<option value="">所有</option>
				<option value="1">用户</option> 
				<option value="2">系统</option>
			</select>
  		
  			<label>&nbsp;&nbsp;&nbsp;&nbsp;清除人：</label>
  			<input id="confirmer" type="text" name="confirmer" />
  			<input type="button" onclick="search();" value="查询" class="searchFormButtonStyle" />
  		</span>
	</div>
	<h2 class="title-h2"><span><img src="${pageContext.request.contextPath}/style/default/bsm/images/arrow-down.gif"/></span>资源事件查询列表</h2> 
	<div class="toolbar" id = "toolbar">
		<a class="page_add renlin" href="javascript:batchAck();">认领</a>
 		<a class="page_delete clear_1" href="javascript:batchConfirm();">清除</a>
 		<a class="page_excel" href="javascript:eventDown();">导出</a>
	</div>
	<div>
	<table id="depmtList"  width="100%" cellpadding="0" cellspacing="0" border="0" class="display" >
		<thead>
			<tr>
				<th width="20"><input style="position:static;" type='checkbox' name='dt_check_all'
					id="dt_check_all" onclick="allClick()" /></th>
				<th width="30">状态</th>
				<th width="30">级别</th>
				<th>事件内容</th>
				<th width="220">事件类别</th>					
				<th width="220">资源名称</th>
				<th width="150">产生时间</th>
				<th width="100">清除人</th>
			</tr>
		</thead>
	</table>
	</div>
  </body>
</html>